import java.util.*;

public class BinarySearch {
    public int getPos(int[] A, int n, int val) {
        int low = 0;
        int high = n;
        int res = -1;
        while(low != high) {
            int mid = (low+high)/2;
            if(A[mid] > val) {
                high = mid;
            }else if(A[mid] < val) {
                low = mid;
                if(res != -1) {     //第一次找到就跳出，否则返回-1
                    break;
                }
            }else {
                res = mid;
                high = mid;
            }
        }
        return res;
    }
}